package com.usian.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.ResponseResult;
import com.usian.common.util.BeanHelper;
import com.usian.model.user.dtos.UserInfoDto;
import com.usian.model.user.dtos.UserRelationDto;
import com.usian.user.entity.ApUser;
import com.usian.user.entity.ApUserFollow;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.user.service.IApUserService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP用户信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "APP用户信息表接口")
@CrossOrigin
public class ApUserController{

    @Autowired
    private IApUserService apUserService;

    /**
     * 关注或取消关注
     * @param dto
     * @return
     */
    @PostMapping("/user_follow")
    public ResponseResult follow(@RequestBody UserRelationDto dto) {
        apUserService.follow(dto);
        return ResponseResult.ok();
    }

//    查询当前登录用户是否关注过文章作者
    @GetMapping("/isUserFollow")
    public Boolean findByUserIdAndFollowId(@RequestParam(name = "userId") Integer userId,
                                           @RequestParam(name = "followId") Integer followId){
       //查询是否关注
        ApUserFollow apUserFollow = apUserService.findByUserIdAndFollowId(userId,followId);
        if (apUserFollow != null){
            //已关注
            return true;
        }
        //未关注
        return false;
    }

//    根据用户id查询用户信息
    @GetMapping("/{id}")
    public UserInfoDto findById(@PathVariable("id") Integer id){
        ApUser apUser = apUserService.getById(id);
        return BeanHelper.copyProperties(apUser,UserInfoDto.class);
    }


}
